<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    
    <script>
        // 1、已知persons用户信息数据：

        // let persons = [
        //     { "username": "xiaoming1", "password": "1111" },
        //     { "username": "xiaoming2", "password": "222" },
        //     { "username": "xiaoming3", "password": "33333" }
        // ]

        // 2、现有 let user = { username: "admin1", password: "12345" }

        // 登录原理：
        // 如果persons中含有对应的用户名和密码则提示登录成功，否则提示用户名和密码错误
        // 注册原理：
        // 如果persons中没有对应的用户，则把user追加到persons末尾
        let persons = [
            { "username": "xiaoming1", "password": "1111" },
            { "username": "xiaoming2", "password": "222" },
            { "username": "xiaoming3", "password": "33333" }
        ]
        let user = { username: "admin1", password: "12345" }
        // let user ={ "username": "xiaoming1", "password": "1111" }



       
        // 登录
        let admin =persons.find(item=>user.username === item.username && user.password ===item.password)
        if(admin){
            document.write('登录成功')
        }else{
            document.write('用户名或密码错误')   
        }
        document.write('<br>')
         // 注册
         let tag = persons.find(item =>item.username === user.username)
        if(tag){
            document.write('该用户已注册')
        }else{
            document.write('注册成功')
            persons.push(user)
            console.log(persons);
        }

       

    </script>
</body>

</html>